<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>学生管理系统</title>
</head>
<body>
    <h1>用户登录</h1>
    <input type="text" id="username">
    <input type="text" id="password">
    <div style="margin-top: 20px;">
        <button id="loginBtn">登录</button>
        <button id="registerBtn">注册</button>
    </div>

    <script src="./js/jquery.min.js"></script>

    <script>
        $('#loginBtn').click(function () {
            const username = $('#username').val()
            const password = $('#password').val()

            $.ajax({
                url: '/users/login',
                data: {
                    username: username,
                    password: password
                },
                type: 'post',
                success: function (res) {
                    if (res.status === 200) {
                        window.location.href = '/'
                    } else {
                        alert(res.msg)
                    }
                }
            })
        })
        $('#registerBtn').click(function () {
            window.location.href = '/register.html'
        })
    </script>
</body>
</html>